package com.yitao.cms.service.order;

import com.skipper.base.service.GenericEntityService;
import com.yitao.client.constant.OrderConstant;
import com.yitao.client.constant.OrderStatusEmnu;
import com.yitao.client.dto.order.MallOrderCouponsDto;
import com.yitao.client.model.order.MallOrderCouponsModel;
import com.yitao.client.model.order.QMallOrderCouponsModel;
import com.yitao.client.model.order.QMallOrderModel;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import java.util.List;

@Service
public class CmsMallOrderCouponsService extends GenericEntityService<MallOrderCouponsModel, MallOrderCouponsDto, QMallOrderCouponsModel> {
    public CmsMallOrderCouponsService(EntityManager entityManager) {
        super(entityManager);
    }

    /**
     * 查询优惠券信息
     */
    public List<MallOrderCouponsModel> getMallOrderCouponsModelListByOrderId(Long orderId) {
        return queryFactory.select(Q).from(Q).where(Q.deleteStatus.eq(Boolean.FALSE).and(Q.orderId.eq(orderId))).fetch();
    }

    /**
     * 根据优惠券ID查看优惠券订单信息
     * @param CouponsId
     * @return
     */
    public List<MallOrderCouponsModel> getMallOrderCouponsModelListByCouponsId(Long CouponsId) {
       // QMallOrderModel qMallOrderModel = QMallOrderModel.mallOrderModel;
      List<MallOrderCouponsModel> list =  queryFactory.select(Q).from(Q).where(Q.deleteStatus.eq(Boolean.FALSE).and(Q.couponsId.eq(CouponsId)))
              /*  .leftJoin(qMallOrderModel).on(Q.orderId.eq(qMallOrderModel.id))
                .where(qMallOrderModel.payStatus.eq(OrderStatusEmnu.PAY_STATUS.HAVE_PAY.getCode())//已支付
                .and(qMallOrderModel.orderType.eq(OrderConstant.OrderTypeEnum.ORDINARY_ORDER.getCode())))//商城订单*/
                .fetch();
        return list;
    }
}
